﻿﻿using Photograp.Models;
using Photograp.Properties;
using System.Data.Entity;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Security;
using WebMatrix.WebData;
using System.Linq;
using System.Collections.Generic;

namespace Photograp
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Database.SetInitializer(new DropCreateIfChangeInitializer());
            var context = new PhotographContext();
            context.Database.Initialize(true);

            //var album = new Album() { Description = "caca", Name = "huete" };
            //album.Photos = new List<Photo>();
            //album.Photos.Add(new Photo
            //{
            //    Description = "Ma première photo",
            //    UrlPhoto = @"http://photograph.blob.core.windows.net/photos/photo_121120132040.jpg"
            //});

            //context.Albums.Add(album);
            //context.SaveChanges();

            WebSecurity.InitializeDatabaseConnection("PhotographContext", "UserProfiles", "UserProfileId", "UserName", autoCreateTables: true);

            if (!Roles.RoleExists(Settings.Default.DefaultRole))
                Roles.CreateRole(Settings.Default.DefaultRole);

            if (!Roles.RoleExists(Settings.Default.AdminRole))
                Roles.CreateRole(Settings.Default.AdminRole);
        }
    }
}